let uid = 0
// 初始化Dep构造函数
export default function Dep() {
  this.uid = ++uid
  this.subs = []
  this.subIds = new Set()
}
// 挂载addSub方法
Dep.prototype.addSub = function (sub) {
  if (!this.subIds.has(sub.id)) {
    this.subs.push(sub)
    this.subIds.add(sub.id)
  }
}
// 挂载depend方法
Dep.prototype.depend = function () {
  if (Dep.target) {
    Dep.target.addDep(this)
  }
}
// 挂载notify方法，通知所有订阅者
Dep.prototype.notify = function () {
  this.subs.forEach(function (sub) {
    sub.update()
  })
}
Dep.target = null
const targetStack = []
// 添加
export function pushTarget(target) {
  targetStack.push(target)
  // 赋值Dep.target
  Dep.target = target
}
// 弹出
export function popTarget() {
  targetStack.pop()
  // 赋值Dep.target
  Dep.target = targetStack[targetStack.length - 1]
}